home *** CD-ROM | disk | FTP | other *** search
/ Aminet 51 / Aminet 51 (2002)(GTI - Schatztruhe)[!][Oct 2002].iso / Aminet / util / arc / xadmasterdev.lha / xad / Sources / ExampleClient.c
Encoding:
C/C++ Source or Header  |  2002-08-20  |  6.4 KB  |  181 lines

  1. #ifndef XADMASTER_EXAMPLE_C
  2. #define XADMASTER_EXAMPLE_C
  3.  
  4. /* Programmheader
  5.  
  6.     Name:        Example.c
  7.     Main:        xadmaster
  8.     Versionstring:    $VER: Example.c 1.4 (02.12.2001)
  9.     Author:        SDI
  10.     Distribution:    Freeware
  11.     Description:    Example disk or file archiver client
  12.  
  13.  1.0   16.02.99 : first version
  14.  1.1   20.06.99 : some little corrections
  15.  1.2   29.06.99 : now uses master free stuff
  16.  1.3   24.02.00 : added some more comments
  17.  1.4   02.12.01 : update to current state
  18. */
  19.  
  20. #include <proto/xadmaster.h>
  21. #include <dos/dos.h>
  22. #include "SDI_compiler.h"
  23.  
  24. #ifndef XADMASTERFILE
  25. #define Example_Client        FirstClient
  26. #define NEXTCLIENT        0
  27. #define XADMASTERVERSION    11
  28. UBYTE version[] = "$VER: Example 1.4 (02.12.2001)";
  29. #endif
  30. #define EXAMPLE_VERSION        1
  31. #define EXAMPLE_REVISION    4
  32.  
  33. /* This is an empty example client! You should replace all "EXAMPLE"
  34. texts with text related to your own client. */
  35.  
  36. /* NOTE: I normally use SAS-C. This compiler supports local base variables
  37. for library calls, so all function calls to xadmaster.library can be done
  38. using the argument passed in register A6.
  39.  
  40. If your compiler does not support that, insert a global base, rename the
  41. argument of the functions to lower case xadmasterbase and add following
  42. line in Example_GetInfo() function:
  43.  
  44.   xadMasterBase = xadmasterbase;
  45.  
  46. xadMasterBase also has a pointer to DOSBase and SysBase, but normally this
  47. should not be necessary, but it is useful for debug output in test versions.
  48. */
  49.  
  50. /* See the included example clients as well! */
  51.  
  52. ASM(BOOL) Example_RecogData(REG(d0, ULONG size), REG(a0, STRPTR data),
  53. REG(a6, struct xadMasterBase *xadMasterBase))
  54. {
  55.   if(/* do some checks here (headerID, header checksum, ...) */)
  56.     return 1; /* known file */
  57.   else
  58.     return 0; /* unknown file */
  59. }
  60.  
  61. ASM(LONG) Example_GetInfo(REG(a0, struct xadArchiveInfo *ai),
  62. REG(a6, struct xadMasterBase *xadMasterBase))
  63. {
  64.   /* return an error code, as long as function is empty */
  65.   return XADERR_NOTSUPPORTED;
  66.  
  67.   /* Always do this function first (after RecogData). Normally it's the
  68.   easiest one.
  69.   General style for file archivers:
  70.   -Allocate "xadAllocObject(XADOBJ_FILEINFO, ...., TAG_DONE)" the
  71.    xadFileInfo structure for every file and fill it's fields with
  72.    correct values (date, size, protection, crunched size, flags, ...).
  73.   -Add the allocated structure to a linked list, which is assigned to
  74.    ai->xai_FileInfo.
  75.    This is done using xadAddFileEntry or xadAddDiskEntry functions.
  76.   -If an error occurs set "ai->xai_Flags & XADAIF_FILECORRUPT" or
  77.    return the error if it is really serious. If there are already valid
  78.    entries in linked list, there cannot be that serious!
  79.   -Leave this function.
  80.   General style for disk archivers:
  81.   -Allocate "xadAllocObject(XADOBJ_DISKINFO, ...., TAG_DONE)" the
  82.    xadDiskInfo structure for every file and fill it's fields with
  83.    correct values (tracks, heads, flags, ...).
  84.   -Add the allocated structure to a linked list, which is assigned to
  85.    ai->xai_DiskInfo.
  86.   -If there are information texts, create a linked list with xadTextInfo
  87.    structures. These are allocated with xadAllocObjectA(XADOBJ_TEXTINFO, 0).
  88.   -If an error occurs set "ai->xai_Flags & XADAIF_FILECORRUPT" or
  89.    return the error if it is really serious. If there are already valid
  90.    entries in linked list, it cannot be that serious!
  91.   -Leave this function.
  92.  
  93.   For nearly all archivers it is necessary to store current file position
  94.   (ai->xai_InPos), to be able to find the data in unarchive function.
  95.   Therefor xid_DataPos and xfi_DataPos exists. You can use the flags
  96.   XADFIF_SEEKDATAPOS or XADIF_SEEKDATAPOS and the seek is done automatically
  97.   when unarchiving is called.
  98.  
  99.   Get data using "xadHookAccess(XADAC_READ, size, buf, ai)" and seek input
  100.   data using "xadHookAccess(XADAC_INPUTSEEK, size, 0, ai)".
  101.   */
  102. }
  103.  
  104. ASM(LONG) Example_UnArchive(REG(a0, struct xadArchiveInfo *ai),
  105. REG(a6, struct xadMasterBase *xadMasterBase))
  106. {
  107.   /* return an error code, as long as function is empty */
  108.   return XADERR_NOTSUPPORTED;
  109.  
  110.   /*
  111.   -Either use ai->xai_CurDisk or ai->xai_CurFile and seek the input data
  112.    to the position required to access the archived data for the wanted entry:
  113.    "xadHookAccess(XADAC_INPUTSEEK, pos-ai->xai_InPos, 0, ai)".
  114.    Alternatively you can use XADFIF_SEEKDATAPOS and XADIF_SEEKDATAPOS in
  115.    GetInfo and the seek is done automatically.
  116.   -Extract the data using XADAC_READ for reads, XADAC_WRITE for storing data
  117.    or XADAC_COPY for copying the data directly.
  118.   - Leave the function either returning 0 or an errorcode, which occured.
  119.   */ 
  120. }
  121.  
  122. ASM(void) Example_Free(REG(a0, struct xadArchiveInfo *ai),
  123. REG(a6, struct xadMasterBase *xadMasterBase))
  124. {
  125.   /* This function needs to free all the stuff allocated in info or
  126.   unarchive function. It may be called multiple times, so clear freed
  127.   entries!
  128.   */
  129.  
  130.   /* The following example frees file and disk archive data. It assumes,
  131.   that disk archive information texts are allocated using xadAllocVec and all
  132.   the other stuff (file names, comments, ...) is allocated using the tags
  133.   of xadAllocObject function.
  134.  
  135.   If you only do that stuff, then set the responding XADCF_FREE flags and
  136.   the master library does the stuff for you. In that case you do not even
  137.   need that function (remove it totally!).
  138.  
  139.   In any other case you should modify that function to meet your special
  140.   requirements. Remember. The function should leave all fields cleared!
  141.   */
  142.  
  143.   struct xadFileInfo *fi, *fi2;
  144.   struct xadDiskInfo *di, *di2;
  145.   struct xadTextInfo *ti, *ti2;
  146.  
  147.   for(fi = ai->xai_FileInfo; fi; fi = fi2)
  148.   {
  149.     fi2 = fi->xfi_Next;
  150.     xadFreeObjectA(fi, 0);
  151.   }
  152.   ai->xai_FileInfo = 0;
  153.  
  154.   for(di = ai->xai_DiskInfo; di; di = di2)
  155.   {
  156.     di2 = di->xdi_Next;
  157.     
  158.     for(ti = di->xdi_TextInfo; ti; ti = ti2)
  159.     {
  160.       ti2 = ti->xti_Next;
  161.       if(ti->xti_Text)
  162.         xadFreeObjectA(ti->xti_Text, 0);
  163.       xadFreeObjectA(ti, 0);
  164.     }
  165.     xadFreeObjectA(di, 0);
  166.   }
  167.   ai->xai_DiskInfo = 0;
  168. }
  169.  
  170. /* You need to complete following structure! */
  171. const struct xadClient Example_Client = {
  172. NEXTCLIENT, XADCLIENT_VERSION, XADMASTERVERSION, EXAMPLE_VERSION, EXAMPLE_REVISION,
  173. /* Here the size the client really needs to detect the filetype must be
  174. inserted */, /* XADCF_DISKARCHIVER and/or XADCF_FILEARCHIVER and some of
  175. XADCF_FREEDISKINFO|XADCF_FREEFILEINFO|XADCF_FREETEXTINFO|XADCF_FREETEXTINFOTEXT */,
  176. 0 /* Type identifier. Normally should be zero */, "Example",
  177. (BOOL (*)()) Example_RecogData, (LONG (*)()) Example_GetInfo,
  178. (LONG (*)()) Example_UnArchive, /* 0 or (void (*)()) Example_Free */};
  179.  
  180. #endif /* XADASTER_EXAMPLE_C */
  181.